
var pagenewtrip=1;
function is_numeric (mixed_var) {
  return (typeof(mixed_var) === 'number' || typeof(mixed_var) === 'string') && mixed_var !== '' && !isNaN(mixed_var);
}
function countdaydata()
{
if($( ' input[name="startdate[]"]' ).val()&&$( ' input[name="enddate[]"]' ).val())
{

var days=getDaysBetweenDates($( ' input[name="startdate[]"]' ).val(), $( ' input[name="enddate[]"]' ).val()) ;

$('input[name="day[]"]').val((days+1) );
$('input[name="night[]"]').val((days) );


}


}
function addformnewtrip()
{
    var rownow=rowdiv;
   $("#firstaddform").append(dataform['newtrip1']);
   $("#firstaddform").append('<div class="featureclass">'+dataform['newtrip']+'</div>');
   $("#pageaddfeature2").append(dataform['newtrip2']);
   $("#pageaddfeature3").append(dataform['newtrip3']);
  
  
  $( ' input[name="startdate[]"]' ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( ' input[name="enddate[]"]' ).datepicker( "option", "minDate", selectedDate );
countdaydata();
}
});
  $( ' input[name="enddate[]"]' ).datepicker({
defaultDate: "+1w",
changeMonth: true,
numberOfMonths: 1,
dateFormat:'dd/mm/yy',
onClose: function( selectedDate ) {
$( ' input[name="startdate[]"]' ).datepicker( "option", "maxDate", selectedDate );
        countdaydata();
}
});
   
   $('input[name="samecontactprofile[]"]').click(function() {
    
    if($(this).is(":checked"))
    {
    
    $.post(serviceinfo+'getmyuser', { select:['facebook','twitter','googleplus','email','website','phone','fax','etc'] }, function(data) {
    
    
           if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
          if(data['data']['facebook'])$('input[name="facebook[]"]').val(data['data']['facebook']); 
          if(data['data']['twitter'])$('input[name="twitter[]"]').val(data['data']['twitter']); 
          if(data['data']['googleplus'])$('input[name="googleplus[]"]').val(data['data']['googleplus']); 
          if(data['data']['email'])$('input[name="email[]"]').val(data['data']['email']);
          if(data['data']['website'])$('input[name="website[]"]').val(data['data']['website']);
          if(data['data']['phone'])$('input[name="phone[]"]').val(data['data']['phone']);
          if(data['data']['fax'])$('input[name="fax[]"]').val(data['data']['fax']);
          if(data['data']['etc'])$('textarea[name="etc[]"]').val(data['data']['etc']);
         
         }
    
    
    });
    
    }
    
    
    });
  
  
  
    $(".nextBtn").click(function() {
   
    if(pagenewtrip==1)
    {
    
     if($('#firstaddform input[name="title"]').val()=="")
    {
    alertwrongboxmsgonly('Please Input Title');
    return false;
    }
    else if($('#firstaddform select[name="destination"]').val()=="")
    {
    
    alertwrongboxmsgonly('Please Select Destination');
    return false;
    }
    else if($('#lastaddform input[name="imgmid[]"]').val()=="")
    {
    
    alertwrongboxmsgonly('Please Select Thumbnail');
    return false;
    }
     
    $(".wrpBtnAddCtnt").addClass('wrpBtnAddTrip');
    $(".wrpBtnAddCtnt").addClass('clearfix');
    $(".wrpBtnAddCtnt").removeClass('wrpBtnAddCtnt');
    
    
    $(".nextBtn").addClass('btnNext');
    $(".wrpAuthUpdtAddCtnt").hide();
   $("#pageaddfeature1").hide();   
   $("#pageaddfeature2").show(); 
   $(".backBtn").show(); 
    pagenewtrip++;
    }
    else if(pagenewtrip==2)
    {
     if($('#pageaddfeature2 input[name="day[]"]').val()=="")
    {
    alertwrongboxmsgonly('Please Input Day');
    return false;
    }else if(!is_numeric($('input[name="day[]"]').val()))
    {
        alertwrongboxmsgonly('Please Input Day Numeric');
    return false;
    
    
    }
    
     else if($('#pageaddfeature2 input[name="startdate[]"]').val()=="")
    {
    
    alertwrongboxmsgonly('Please Input StartDate');
    return false;
    }else if($('#pageaddfeature2 input[name="enddate[]"]').val()=="")
    {
    
    alertwrongboxmsgonly('Please Input Enddate');
    return false;
    }
    
    $("#pageaddfeature2").hide();
    $("#pageaddfeature3").show();  

    $(".nextBtn").val('Finish');
    pagenewtrip++;
    
    var dayint=parseInt($('input[name="day[]"]').val(),10);
    if(is_numeric($('input[name="day[]"]').val())&&dayint>0&&$('input[name="startdate[]"]').val()!="")
    {
        var newrow=0;
        var nrow=$('.addTripPlg').length;
        
        if(nrow==0)
        {
            newrow=dayint;
        
        }else if(dayint>nrow)
        {
           newrow= dayint-nrow;
        }else
        {
           if(nrow>dayint)
           {
            deleterow=nrow-dayint;
             
              for(var irow=0;irow<deleterow;irow++)
             {
             var nrow2=$('.addTripPlg').length;
             $('.addTripPlg').eq( nrow2-1 ).remove();
             
             }
           }
          
        
        }
        
        
        if(newrow)
        {

        
        var code='';
        for(var irow=0;irow<newrow;irow++)
        {
        
        code += '<div class="itPlg addTripPlg">\n';
        code += '<div class="wrpPlg clBg5 clBd2 bdFull">\n';
        code += '<div class="plgArea"></div>\n';
        code += '<div class="wrpOutAtcPlg">\n';
        code += '<div class="wrpAtcPlg">\n';
        code += '<div class="spnHdDayTrip clTxtW">\n';
        code += '<span class="fs03">Day 1</span><br>\n';
        code += '<span class="rcmSizeAdd fs01">24/05/2013</span>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '<div class="wrpPlgAreaTrip Clearfix">\n';
        code += '<div class="plgAreaNewTrip clearfix" style="left:.5px">\n';
        code += '<div class="wrpBtnAddNewTrip wrpInNewTrip"  style="width:206px;height:206px;margin:1px">\n';
        code += '<img alt="img" src="'+baseinfo+'/img/newtrip.png">\n';
        code += '<div class="addTxtNewTrip fs04 clTxt3 boldGen"><span>Add thing to do.</span></div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>';
        
        }
        $("#pageaddfeature3 .wrpAddCtnt.clBg4.clBd2.bdFull").append(code);
        
        }
        
        var startdateset=$('input[name="startdate[]"]').val();
        var n0=startdateset.split("/"); 
        var d1 = new Date(n0[2],parseInt(n0[1],10)-1,parseInt(n0[0],10));
    
        var rownum=0;
        
        $( ".addTripPlg" ).each(function( index ) {
        
            $(this).attr("id",'rowdaynumset-'+(rownum+1));
            $(this).find('span.fs03').html('Day '+(rownum+1));
            $(this).find('span.rcmSizeAdd.fs01').html(startdateset);
            $(this).find('.wrpBtnAddNewTrip.wrpInNewTrip').attr("onclick",'openpopupnewtrip('+(rownum+1)+')');
            
            
            

            d1.setTime(d1.getTime() +  ((0+1) * 24 * 60 * 60 * 1000));
            startdateset=d1.format("dd/mm/yyyy");
            
            rownum++;
        
        
        });
    
    
    }
    
   genmapnewtrip(); 
    }
    
    else if(pagenewtrip==3)
    {
    
    $('#formaddfeature').submit();
    
    

    }
    
    });
    
    $(".backBtn").click(function() {
    
    if(pagenewtrip==2)
    {

    $(".wrpBtnAddTrip").addClass('wrpBtnAddCtnt');
    $(".wrpBtnAddTrip").removeClass('clearfix');
    $(".wrpBtnAddTrip").removeClass('wrpBtnAddTrip');
        
        $(".nextBtn").removeClass('btnNext');
        $(".wrpAuthUpdtAddCtnt").show();
       $("#pageaddfeature1").show();   
       $("#pageaddfeature2").hide();
       $(".backBtn").hide(); 
       pagenewtrip--;
       
    } 
    else if(pagenewtrip==3)
    {
        $("#pageaddfeature2").show();
        $("#pageaddfeature3").hide(); 
        $(".nextBtn").val('Next');
        pagenewtrip--;

    }
    
    
    });
 
  
  var code = '<div class="popGenAddTrip posPopAddTrip">\n';
  code += '<div class="topGen clBd2 bdBtm">\n';
  code += '<div class="wrpTtlGen">\n';
  code += '<h1 class="ttlGen clTxt2 fs05">Add Trip</h1>\n';
  code += '</div>\n';
  code += '<div class="btnIco closeGen" onclick="$(\'.ovlPopGen.wrpPopAddNewTrip\').fadeOut();">\n';
  code += '<span class="ico icoCloseGen"></span>\n';
  code += '</div>\n';
  code += '<div class="topBgGen clBg3"></div>\n';
  code += '</div>\n';
  code += '<div class="bodyGen clBg3">\n';
  code += '<div class="bodyOutGen">\n';
    code += '<div class="bodyInGen">\n';
    code += '<div class="wrpTgHdGen clTxt2 fs04">\n';
    code += '<span class="tgHdGen tgCl clBd2 bdR clSp2" onclick="changecelltrip(1)">My Posts</span>\n';
    code += '<span class="tgHdGen tgCl clBd2 bdR" onclick="changecelltrip(2)">My Favorite</span>\n';
    code += '<span class="tgHdGen tgCl clBd2 " onclick="changecelltrip(3)">Activity</span>\n';
    
    //code += '<span class="tgHdGen tgCl clBd2 bdR">New Post</span>\n';
    
    code += '<span class="tgHdGen tgCl clBd2 bdR" style="display:none">Recommend</span>\n';
    code += '<span class="tgHdGen tgCl clBd2" style="display:none">Search</span>\n';
    code += '</div>\n';
    code += '<div class="wrpFrmGenNewTrip">\n';
    code += '<div class="bodyAddNewTrip clBg4 clBd2 bdFull">\n';
    code += '<div class="wrpOutAddNewMyTrip">\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '<div class="wrpBtnGenNewTrip clearfix">\n';
    code += '<button type="button" class="btnGen btnOk clTxtW cutTxt clBgSp2 fs04" onclick="savetripbyselectdata()">ADD</button>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>\n';
    code += '</div>';
    
    
    $(".ovlPopGen.wrpPopAddNewTrip").html(code);
  
    
  
  
  
  
  
    
  
  //$('#feature'+rownow+' .group')
   
   
  
   

  
  
   rowdiv++;
}
function getformnewtrip(dataplugin)
{

var code = '<div class="ldIt wrpPmtLd">\n';
code += '<div class="wrpPmtLd">\n';
code += '<h2 class="clTxt2 fs04">Duration</h2>\n';
code += '<div class="pmtLd">\n';
code += '<span class="boldGen">'+dataplugin.day+' Days '+dataplugin.night+' Night</span>\n';



if(dataplugin.enddate!="0000-00-00")
{

code += '(<span>'+dataplugin.startdate2+'</span>\n';
code += '<span> - </span>\n';
code += '<span>'+dataplugin.enddate2+'</span>)\n';
}else
{

var day0=dataplugin.startdate.split("-");

var d1 = new Date(day0[2],parseInt(day0[1],10)-1,parseInt(day0[0],10));


d1.setTime(d1.getTime() +  ((parseInt(dataplugin.day,10)-1) * 24 * 60 * 60 * 1000));


var enddateset2=d1.format("dd/mm/yyyy");




code += '(<span>'+dataplugin.startdate2+'</span>\n';
code += '<span> - </span>\n';
code += '<span>'+enddateset2+'</span>)\n';


}


code += '</div>\n';
code += '</div>\n';
code += '</div>';

if(dataplugin.currencyname!="")
{
code += '<div class="ldIt wrpOutPrcLd mgBtm20">\n';
code += '<div class="wrpPrcLd">\n';
code += '<h2 class="clTxt2 fs04">Price</h2>\n';
var priceset=dataplugin.price;
if(dataplugin.saleprice!="0.00")
{
priceset=dataplugin.saleprice;

}

code += '<span class="prcLd">'+priceset+' '+dataplugin.currencyname+'</span>\n';


code += '</div>\n';
code += '</div>';
}


code += '<div class="wrpCtcInfo">'+"\n";
code += '<div class="wrpHdInfoGen">'+"\n";
code += '<h2 class="clTxt2 fs04">Contact</h2>'+"\n";
code += '</div>'+"\n";
code += '<table class="tbGenInfo tbCtcLd tbAddCtnt clTxt3 fs03">'+"\n";
code += '<tbody>'+"\n";
if(dataplugin.facebook.indexOf("facebook")!=-1)
{
var datafacebook=dataplugin.facebook;
if(dataplugin.facebook.indexOf("http")==-1)
{
    datafacebook="http://"+dataplugin.facebook;

}


code += '<tr>\n';
code += '<th>Facebook</th>\n';
code += '<td><a href="'+datafacebook+'" target="_blank">'+datafacebook+'</a></td>\n';
code += '</tr>\n';
}
if(dataplugin.twitter.indexOf("twitter")!=-1)
{
var datatwitter=dataplugin.twitter;
if(dataplugin.twitter.indexOf("http")==-1)
{
    datatwitter="http://"+dataplugin.twitter;

}
code += '<tr>\n';
code += '<th>Twitter</th>\n';
code += '<td><a href="'+datatwitter+'" target="_blank">'+datatwitter+'</a></td>\n';
code += '</tr>\n';
}
if(dataplugin.googleplus.indexOf("google")!=-1)
{
var datatgoogleplus=dataplugin.googleplus;
if(dataplugin.googleplus.indexOf("http")==-1)
{
    datatgoogleplus="http://"+dataplugin.googleplus;

}

code += '<tr>\n';
code += '<th>Google+</th>\n';
code += '<td><a href="'+datatgoogleplus+'" target="_blank" >'+datatgoogleplus+'</a></td>\n';
code += '</tr>\n';

}
if(dataplugin.website)
{
if(ValidUrl(dataplugin.website))
{
code += '<tr>\n';
code += '<th>Website</th>\n';
code += '<td><a href="'+dataplugin.website+'" target="_blank" >'+dataplugin.website+'</a></td>\n';
code += '</tr>\n';
}
}
if(dataplugin.email)
{
if(validateEmail(dataplugin.email))
{
code += '<tr>\n';
code += '<th>Email</th>\n';
code += '<td>'+dataplugin.email+'</td>\n';
code += '</tr>\n';
}
}
if(dataplugin.phone)
{
code += '<tr>\n';
code += '<th>Phone</th>\n';
code += '<td>'+dataplugin.phone+'</td>\n';
code += '</tr>\n';
}
if(dataplugin.fax)
{
code += '<tr>\n';
code += '<th>Fax</th>\n';
code += '<td>'+dataplugin.fax+'</td>\n';
code += '</tr>\n';
}
if(dataplugin.etc)
{
code += '<tr>\n';
code += '<th>ETC</th>\n';
code += '<td>'+dataplugin.etc+'</td>\n';
code += '</tr>\n';
}
code += '</tbody>\n';
code += '</table>\n';

code += '</div>\n';


if(Object.keys(dataplugin.objdata).length>0)
{
var arraydata=dataplugin;

//code="";
code+= '<div class="ldIt wrpMapLd clBg4 w640 mapdataroute" >'
code+= '<div class="icoDefLd">'
code+= '<span class="ico icoMapDefLd"></span>'
code+= '<span>Map</span>'
code+= '</div>'
code+= '</div>';
var rowdata=1;
var rowdata2=1;
 var rowset=0;
 var alphabet = new Array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z');

$.each(arraydata['objdata'], function(keydata, valueobjdata) {

code+= '<div class="ldIt wrpMyTripLd clBg4 w640 clearfix">'
code+= '<div class="wrpAtcPlg">'
code+= '<div class="spnHdDayTrip clTxtW">'
code+= '<span class="fs03">Day '+rowdata+'</span><br>'
code+= '<span class="rcmAddGen fs01">'+keydata+'</span>'
code+= '</div>'
code+= '</div>'
code+= '<div class="wrpPlgAreaTrip">'
code+= '<div class="plgAreaTrip clearfix">'
if(Object.keys(valueobjdata).length>0)
{



 $.each(valueobjdata, function(keydata, valuedata2) {
 
 
 if(valuedata2['isactivity']!="0")
 {

code+= '<div class="wrpInCell wrpInCellTrip w158 wrpActCell" style="margin:1px" onclick="popupactivites(\''+valuedata2['title']+'\',\''+valuedata2['description']+'\')">'
code+= '<div class="ovlCellTrip w158"></div>'

code+= '<a href="javascript:void(0)"  class="galleryimage"><img height="158" title="'+valuedata2['img']['newpath']+'" width="158" alt="img" src="'+valuedata2['simg']['newpath']+'" class="imgCell w158"></a>'
code+= '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'+valuedata2['title']+'</div>'
code+= '<div class="timeTrip clTxtW fs01">'+valuedata2['plandate2']+'</div>'
code+= '<div class="pointTrip">'
code+= '<span class="clTxtW fs02">'+rowdata2+'</span>'
code+= '</div>'
code+= '</div>';

rowdata2++;
 
 }else
 {
 var lat="";
 var lng="";
 if( valuedata2['data'])
 {
 if(Object.keys(valuedata2['data']['plugins']).length>0)
 {
  $.each(valuedata2['data']['plugins'], function(keydata, valueplugins) {
  
 
 if(valueplugins['plugid']==5)
 {
 lat=valueplugins['lat'];
 lng=valueplugins['lng'];
 
 }
 
 });
 
 }
 
 
code+= '<div class="wrpInCell wrpInCellTrip w158 pointTripData" onclick="linkto(\''+baseinfo+'/'+valuedata2['data']['link']+'/'+valuedata2['data']['productid']+'\')" style="margin:1px">'
code+= '<div class="ovlCellTrip w158"></div>'
code+= '<a href="'+baseinfo+'/'+valuedata2['data']['link']+'/'+valuedata2['data']['productid']+'" target="_blank"><img height="158" width="158" alt="img" src="'+valuedata2['data']['simg']['newpath']+'" class="imgCell w158"></a>'
code+= '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'+valuedata2['data']['title']+'</div>'
code+= '<div class="timeTrip clTxtW fs01">'+valuedata2['plandate2']+'</div>'
code+= '<div class="pointTrip">'
code+= '<span class="clTxtW fs02">'+alphabet[rowset]+'</span>'
code+= '</div><input type="hidden" value="'+lng+'" name="lngset[]"><input type="hidden" value="'+lat+'" name="latset[]">'
code+= '</div>';
rowset++;
}
 
 }
 
 
 });
 }

code+= '</div>'


code+= '</div>'
code+= '</div>';


rowdata++;




});




}

return code;


}
function saveformnewtrip(id,plugid)    
{
    var obj={};  
    var id="formaddfeature";
    var alltime,openhours,closehours,infomation,sameaddressprofile,address,countryid,proid,disid,tumid,state,code,samecontactprofile,facebook,twitter,googleplus,email,website,phone,fax,etc,dayset,nightset,startdateset,enddateset,priceset,salepriceset,curidset,destinationset,day0,day1;
    
  samecontactprofile=$("#"+id+' input[name="samecontactprofile[]"]').is(':checked');
        if(samecontactprofile)
        {
        samecontactprofile=$("#"+id+' input[name="samecontactprofile[]"]').val();
        facebook="";
        twitter="";
        googleplus="";
        email="";
        website="";
        phone="";
        fax="";
        etc="";

        }else
        {
        samecontactprofile=0;
        facebook=$("#"+id+' input[name="facebook[]"]').val();
        twitter=$("#"+id+' input[name="twitter[]"]').val();
        googleplus=$("#"+id+' input[name="googleplus[]"]').val();
        email=$("#"+id+' input[name="email[]"]').val();
        website=$("#"+id+' input[name="website[]"]').val();
        phone=$("#"+id+' input[name="phone[]"]').val();
        fax=$("#"+id+' input[name="fax[]"]').val();
        etc=$("#"+id+' textarea[name="etc[]"]').val();



        }
        
        dayset=$("#"+id+' input[name="day[]"]').val();
        nightset=$("#"+id+' input[name="night[]"]').val();
        day0=$("#"+id+' input[name="startdate[]"]').val().split("/");
        enddateset=$("#"+id+' input[name="enddate[]"]').val();
        priceset=$("#"+id+' input[name="price[]"]').val();
        salepriceset=$("#"+id+' input[name="saleprice[]"]').val();
        curidset=$("#"+id+' select[name="curid[]"]').val();
        destinationset=$("#"+id+' select[name="destination"]').val();
        
        if(enddateset!="")
        {
        day1=enddateset.split("/");;
        enddateset=day1[2]+'-'+day1[1]+'-'+day1[0]
        
        }
        
        
        
        var objdata=new Array();
        var rowdataset=0;
        
        $.each($(".wrpInCell.wrpInNewTrip.w158.setfeature"), function(index ) { 
        
        
        var t0=$(this).find('input[name="settimedata[]"]').val();
        if(t0!="")
        {
        var n0=$(this).find('input[name="settimedata[]"]').attr('alt');
        //console.log(n0);
        n0=parseInt(n0,10);
        
        
        
       // console.log(n0);
        //console.log(day0);
        
        
        
        var d1 = new Date(day0[2],parseInt(day0[1],10)-1,parseInt(day0[0],10));
        d1.setTime(d1.getTime() +  ((n0-1) * 24 * 60 * 60 * 1000));
        var startdateset2=d1.format("yyyy-mm-dd");
        var timedateset2=$(this).find('input[name="settimedata[]"]').val()
        
        
        
        if($(this).find('input[name="sproductid[]"]').val()=="0")
        {
        objdata[rowdataset]={isactivity:1,description:$(this).find('textarea[name="descritionset[]"]').val(),title:$(this).find('.ldTtlCell.ldTtlTrip.fs05.clTxtCell.cutTxt').html(),simgmid:$(this).find('input[name="simgmid[]"]').val(),imgmid:$(this).find('input[name="imgmid[]"]').val(),day:n0
        
        ,dateset:startdateset2,timeset:timedateset2+':00',plandate:startdateset2+' '+timedateset2+':00'
        
        };
        
        }else
        {
         
        objdata[rowdataset]={isactivity:0,sproductid:$(this).find('input[name="sproductid[]"]').val(),day:n0
        
        
        ,dateset:startdateset2,timeset:timedateset2+':00',plandate:startdateset2+' '+timedateset2+':00'
        
        };
        
        }
        rowdataset++;
        }
        
        });
        
        
        
        obj={plugid:plugid,proid:destinationset,day:dayset,night:nightset,startdate:day0[2]+'-'+day0[1]+'-'+day0[0],enddate:enddateset,price:priceset,saleprice:salepriceset,curid:curidset,samecontactprofile:samecontactprofile,facebook:facebook,twitter:twitter,googleplus:googleplus,email:email,website:website,phone:phone,fax:fax,etc:etc,objdata:objdata};
        
        
        return obj;

}

function savetripbyselectdata()
{
var code='';
if(nowactid==1||nowactid==2)
{


$(".timeNewTrip.shwTimeNewTrip.w238:visible").each(function( index ) {

var idtimetrip=$(this).attr("id");
var rownid=idtimetrip.split("-"); 



var value= setproductidnow[rownid[1]];
var rownid=rownid[1];

code += '<div class="wrpInCell wrpInNewTrip w158 setfeature" style="margin:1px;width:206px;height:206px" id="wrpInNewTrip-'+rownowtripdata+'">\n';

code += '<div class="ovlCellTrip w158"></div>\n';
code += '<img width="158" height="158" alt="img" src="'+value.simg.newpath+'" class="imgCell w158">\n';
code += '<div class="wrpTl wrpBtnEdtCell">\n';
code += '<div title="Remove" class="btnIco closeTl" onclick="deletetriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoCloseTl"></span>\n';
code += '</div>\n';
code += '<div title="Edit" class="btnIco edtCell" onclick="edittriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoEdtCell"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'+value.title+'</div>\n';
code += '<div class="inpTimeTrip clTxtW fs03"><span>'+$('#shwTimeAddNewTrip-'+rownid).html()+'</span></div>\n';

//code += '<input type="hidden" value="'+$('#timestart-'+rownid)+'" alt="settimedata-'+rownowtripdata+'" name="settimedata[]">';


//code += '<div class="pointTrip classpoint">\n';
var checkpoint=0;
var latsettrip=0;
var lngsettrip=0;

if(setproductidnow[rownid].plugins)
{
checkpoint=0;
$.each( setproductidnow[rownid].plugins, function( key, value ) {

if(value.plugname=="map")
{

checkpoint=1;
latsettrip=value.lat;
lngsettrip=value.lng;


}

});


}

if(checkpoint==1)
{
code += '<div class="pointTrip classpoint">\n';

code += '<input type="hidden" value="'+latsettrip+'" name="latsetrip[]">';
code += '<input type="hidden" value="'+lngsettrip+'" name="lngsetrip[]">';
code += '<input type="hidden" value="'+rownid+'" name="productidtrip[]">';


var lengthall=$('.pointTrip.classpoint').length;

code += '<span class="clTxtW fs02">'+pointData[lengthall]+'</span>\n';
code += '</div>\n';
}


code += '<form class="timeNewTrip addTimeNewTrip w238" style="display:none">\n';
code += '<div class="ovlTimeNewTrip"></div>\n';
code += '<div class="wrpTimeNewTrip">\n';
code += '<input type="text" value="'+$('#timestart-'+rownid).val()+'" id="settimedata-'+rownowtripdata+'" alt="'+daysettrip+'" name="settimedata[]" placeholder="Start Time" class="inpAddCtnt w120 clBg5 clBd2 fs03 clTxt2">\n';

code +='<input type="hidden" name="sproductid[]" value="'+value.productid+'" >';



code += '<button type="button" onclick="saveedittimedata('+rownowtripdata+','+daysettrip+')" class="btnGen btnTimeOk clTxtW cutTxt clBgSp2 fs04">OK</button>\n';
code += '</div>\n';
code += '</form>';

rownowtripdata++;


//code +='';

//code += '<span class="clTxtW fs02">A</span>\n';
//code += '</div>\n';
code += '</div>';




});



$('.plgAreaNewTrip.clearfix').eq((daysettrip-1)).append(code);
changetimedatatrip(daysettrip);




}
else if(nowactid==3)
{
if($('#featureactivity input[name="title"]').val()=="")
{
alertwrongboxmsgonly('Please insert Title');
return false;
}
else if($('#featureactivity .inpTimeAddAct').val()=="")
{
alertwrongboxmsgonly('Please insert Time');
return false;
}
else if($('#featureactivity input[name="filelinkcrop[]"]').val()=="")
{
alertwrongboxmsgonly('Please insert Image');
return false;
}

code += '<div class="wrpInCell wrpInNewTrip w158 setfeature" style="margin:1px;width:206px;height:206px" id="wrpInNewTrip-'+rownowtripdata+'">\n';

code += '<div class="ovlCellTrip w158"></div>\n';
code += '<img width="158" height="158" alt="img" src="'+$('#featureactivity input[name="filelinkcrop[]"]').val()+'" class="imgCell w158">\n';
code += '<div class="wrpTl wrpBtnEdtCell">\n';
code += '<div title="Remove" class="btnIco closeTl" onclick="deletetriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoCloseTl"></span>\n';
code += '</div>\n';
code += '<div title="Edit" class="btnIco edtCell" onclick="edittriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoEdtCell"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'+$('#featureactivity input[name="title"]').val()+'</div>\n';

var objectset=convertTo12Hrs("February 04, 2011 "+$('#featureactivity .inpTimeAddAct').val());
//$('#shwTimeAddNewTrip-'+productidset).html(objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch);


code += '<div class="inpTimeTrip clTxtW fs03"><span>'+objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch+'</span></div>\n';





code += '<form class="timeNewTrip addTimeNewTrip w238" style="display:none">\n';
code += '<div class="ovlTimeNewTrip"></div>\n';
code += '<div class="wrpTimeNewTrip">\n';
code += '<input type="text" value="'+$('#featureactivity .inpTimeAddAct ').val()+'" id="settimedata-'+rownowtripdata+'" alt="'+daysettrip+'" name="settimedata[]" placeholder="Start Time" class="inpAddCtnt w120 clBg5 clBd2 fs03 clTxt2">\n';

code +='<input type="hidden" name="sproductid[]" value="0" >';

code +='<input type="hidden" name="simgmid[]" value="'+$('#featureactivity input[name="simgmid[]"]').val()+'" >';
code +='<input type="hidden" name="imgmid[]" value="'+$('#featureactivity input[name="imgmid[]"]').val()+'" >';



code +='<textarea  name="descritionset[]" style="display:none"  >'+$('#featureactivity textarea[name="description"]').val()+'</textarea>';

code += '<button type="button" onclick="saveedittimedata('+rownowtripdata+','+daysettrip+')" class="btnGen btnTimeOk clTxtW cutTxt clBgSp2 fs04">OK</button>\n';
code += '</div>\n';
code += '</form>';


rownowtripdata++;


//code +='';

//code += '<span class="clTxtW fs02">A</span>\n';
//code += '</div>\n';
code += '</div>';

$('.plgAreaNewTrip.clearfix').eq((daysettrip-1)).append(code);
changetimedatatrip(daysettrip);



}

$(".ovlPopGen.wrpPopAddNewTrip").fadeOut();

}


var daysettrip=0;
var pagemainset=1;
var nowactid=1;
function changecelltrip(actid)
{
nowactid=actid;
$(".wrpOutAddNewMyTrip").html('');
if(actid==1||actid==2)
{
pagemainset=1;

getactiondatatrip(actid);
}else
{
createactivitytrip();
}
}
var arrayactive=new Array();
function setactivitydata(keydata)
{
var urlset=baseinfo+'/img/activity/'+arrayactive[keydata]['path'];
var rowsetdatak=keydata;
loaddata();
$.post(serviceinfo+'savelink', { url:urlset }, function(data) {  
loadclosedata();
var rownow='activity';
var rowgnow3=1;

if(data.error.response)
         {
         
          alertbox(data.error.error);
         
         }
else
        {
            
            
            
            
            $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+data.filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+data.filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
             $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(data.imgmid);
             $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(data.filelink);                                    
             $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(data.width);         
             $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(data.height);
         
         
         
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(data.filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(data.imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(data.width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(data.height);
            
            
            
            $('#feature'+rownow+' input[name="title"]').val(arrayactive[rowsetdatak].title);
            $('#feature'+rownow+' textarea[name="description"]').val(arrayactive[rowsetdatak].description);
            
            
        }



});


}
function createactivitytrip()
{
var productxhr=$.get(serviceinfo+'getactivitylist', function(data) { 


var code = '<div class="wrpAddNewAct">\n';
code += '<div class="wrpBscAct clearfix clBd2 bdBtm">\n';
code += '<span class="hdBscAct clTxt2 fs03 boldGen">Basic Activity :</span>\n';
code += '<div class="wrpInBscAct">\n';
if(data.data.length)
{
arrayactive=data['data'];
$.each(data['data'], function(key, value) {


code += '<span class="bscAct clTxt2 fs03 clBg2" onclick="setactivitydata('+key+')">'+value.title+'</span>\n';


});

//code += '<span class="bscAct clTxt2 fs03 clBg2">Breakfast</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Lunch and Napping Time</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Dinner and Leisure Time</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Night Activities</span>\n';
//code += '<span class="bscAct clTxt2 fs03 clBg2">Room Time</span>\n';
}

code += '</div>\n';
code += '</div>\n';
code += '<div class="bodyAddAct">\n';
code += '<form class="wrpFrmGen" id="featureactivity">\n';
code += '<fieldset class="wrpFrmAddAct">\n';
code += '<div class="wrpOutImgAddNewAct">\n';
code += '<div class="wrpTtlImgAddAct">\n';
code += '<h2 class="ttlImgAddAct clTxt2 fs03">Thumbnail</h2>\n';
code += '<p class="rcmImgAddAct clTxt3 fs01">recommended size : 600px X 600px</p>\n';
code += '</div>\n';
code += '<div class="wrpImgAddAct image1">\n';
code += '<div class="imgAddAct clBg5 clBd2 bdFull plgAreaThumbnail">\n';
code += '</div>\n';
code += '<div class="addTnTl clBd2 bdBtm">\n';
code += '<div title="Browse" class="btnIco addImgTl clBd3 bdBtm uploadbutton">\n';
code += '<span class="ico icoAddImgTl"></span>\n';
code += '<div class="wrpUlFile">\n';
//code += '<input type="file" class="ulFile">\n';
code += '</div>\n';
code += '</div>\n';
code += '<div title="Cloud" class="btnIco addCldTl clBd3 bdBtm cloudbutton cloud1">\n';
code += '<span class="ico icoAddCldTl"></span>\n';
code += '</div>\n';
code += '<div title="Link" class="btnIco addLnkTl clBd3 bdBtm linkbutton link1">\n';
code += '<span class="ico icoAddLnkTl"></span>\n';
code += '</div>\n';
code += '<div title="Remove" class="btnIco btnRmvTl deletebutton">\n';
code += '<span class="ico icoRmvTl"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="wrpInfoAddNewAct">\n';
code += '<div class="wrpInpTtlAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Title</label><br>\n';
code += '<input type="text" name="title" class="inpTtlAddNewAct clBg5 clTxt3 fs02">\n';
code += '</div>\n';
code += '<div class="wrpInpDesAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Description</label><br>\n';
code += '<textarea maxlength="128" required="" name="description" class="inpDesAddNewAct clBg5 clTxt3 fs02"></textarea>\n';
code += '</div>\n';
code += '<div class="wrpInpTimeAddAct">\n';
code += '<label class="lbInpAddAct fs03 clTxt2">Start Time</label><br>\n';
code += '<input type="text" class="inpTimeAddAct clBg5 clTxt3 fs02">\n';
code += '</div>\n';
code += '</div>\n';
code += '</fieldset>\n';
code += '</form>\n';
code += '</div>\n';
code += '</div>';
$(".wrpOutAddNewMyTrip").html(code);



var rownow='activity';
var rowgnow=1;
   $('#feature'+rownow+' .image'+rowgnow+' .uploadbutton').iuploader({
         'link':serviceinfo+'iupload',
         'accept':'image/*',
         'group':rowgnow,

         'type':['jpg', 'jpeg', 'png', 'gif'],
         'onUploadFinish':function(filename,filelink,setting){
         
         
         
         
         getpopupboxresize(300,300,filelink,setting['originalwidth'],setting['originalheight'],
         
         function(filename2,filelink2,width2,height2,imgmid2){
         var rowgnow2=setting['group'];
         
         $('#feature'+rownow+' .image'+rowgnow2+' .plgAreaThumbnail').html('<a target="_blank" href="'+filelink+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         

         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelink[]"]').val(filelink);
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="filelinkcrop[]"]').val(filelink2);
         
         
         $('#feature'+rownow+' .image'+rowgnow2+' input[name="fileold[]"]').val(setting.fileold);
         
         $("#width-"+setting.id).val(setting.originalwidth);
         $("#height-"+setting.id).val(setting.originalheight);
         
         
         $("#imgmid-"+setting.id).val(setting.imgmid);
         
         $("#simgmid-"+setting.id).val(imgmid2);
         
         
         $("#widthcrop-"+setting.id).val(width2);
         $("#heightcrop-"+setting.id).val(height2);
         
         closepopup(); 
         
         }
         ,setting['imgmid']
         
         );
         //alert(filename);
         }
   });
  
  
   $('#feature'+rownow+' .image'+rowgnow+' .cloudbutton').click(function() {
          //var rowgnow3=rowgnow;
          var rowgnow3=$(this).attr("class").split('cloud').pop();
        //alert("Handler for .click() called.");
          getpopupcloud(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
         closepopup(); 

          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
            //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
           // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,300
          ,300
          
          );

   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .deletebutton').click(function() {
   
   var rowgnow3=1;
   
   $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail a').remove();
   //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
  // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
  // $('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",'/images/default/noimage640x360.jpg'+'?t='+Math.floor((Math.random()*100000)+1));
   
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val('');           
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val('');
   $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val('');
   
   
   
    $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val('');
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val('');                                    
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val('');         
     $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val('');
   
   });
   
   $('#feature'+rownow+' .image'+rowgnow+' .linkbutton').click(function() {
   var rowgnow3=1;
   
   
   getpopuplink(
          function(filename2,filelink2,width2,height2,imgmid2,index2){ 
          
          
         //$('#feature'+rownow+' .image'+rowgnow3+' img').attr("src",filelink2+'?t='+Math.floor((Math.random()*100000)+1));
         
         $('#feature'+rownow+' .image'+rowgnow3+' .plgAreaThumbnail').html('<a target="_blank" href="'+$('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val()+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="150" width="150" src="'+filelink2+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="simgmid[]"]').val(imgmid2);
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelinkcrop[]"]').val(filelink2);                                    
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="widthcrop[]"]').val(width2);         
         $('#feature'+rownow+' .image'+rowgnow3+' input[name="heightcrop[]"]').val(height2);
      //   $.colorbox.close("User added succesfully"); 
            closepopup();
          
          },
          function(filename,filelink,width,height,imgmid,indexnow){
            
            //$('#feature'+rownow+' .royalSlider  a.rsImg').eq((rowgnow3-1)).attr("href",filelink+'?t='+Math.floor((Math.random()*100000)+1));
          // $('#feature'+rownow+' .rsSlide  img').eq((rowgnow3-1)).attr("src",filelink+'?t='+Math.floor((Math.random()*100000)+1));
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="filelink[]"]').val(filelink);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="imgmid[]"]').val(imgmid);           
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="width[]"]').val(width);
            $('#feature'+rownow+' .image'+rowgnow3+' input[name="height[]"]').val(height);
            

          
          }
          ,
          rowgnow
          ,300
          ,300
   );
   
   });

   $("#feature"+rownow+' .inpTimeAddAct').datepicker( "destroy" ); 
   $("#feature"+rownow+' .inpTimeAddAct').timepicker();


});


}
function genmapnewtrip()
{
var genmappoint={};
var genpoint={};  
var genpointarr=new Array();
var rowgenmap=0;
$.each($('.pointTrip.classpoint'), function(index ) {

genmappoint[rowgenmap]=new google.maps.LatLng($(this).find('input[name="latsetrip[]"]').val(),$(this).find('input[name="lngsetrip[]"]').val())
;
genpointarr[rowgenmap]={latLng:[$(this).find('input[name="latsetrip[]"]').val(), $(this).find('input[name="lngsetrip[]"]').val()], data:$(this).find('span.clTxtW.fs02').html(),options:{icon: iconBase +pointData[rowgenmap]+'_maps.png'}};

genpoint[rowgenmap]={point:$(this).find('.clTxtW.fs02').html()};

rowgenmap++;





});

 
 //console.log(Object.keys(genmappoint).length);   
 $('.itPlg.addMapPlg').show();
if(Object.keys(genmappoint).length>1)
{

  if(Object.keys(genmappoint).length>2)
  {
   var waypts=[];
   var rowwaypts=0;
  $.each(genmappoint, function(index, value) {
       
          if(rowwaypts!=0&&rowwaypts!=(Object.keys(genmappoint).length-1))
          {
          waypts.push(
          {
                location:new google.maps.LatLng(value.lat(),value.lng()),
                stopover:true
          }
          );
          }
          
          
          rowwaypts++;
                     
        //alert(index + ': ' + value);
        
        
        });
        
    var objset= {
        origin:genmappoint[0],
        destination:genmappoint[Object.keys(genmappoint).length-1],
        optimizeWaypoints: true,  
        avoidTolls:true,
        waypoints:waypts,
        avoidHighways:true,
        provideRouteAlternatives:true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };      
  
  
  }else
  {
  var objset= {
        origin:genmappoint[0],
        destination:genmappoint[Object.keys(genmappoint).length-1],
        optimizeWaypoints: true,  
        avoidTolls:true,
        avoidHighways:true,
        provideRouteAlternatives:true,
        travelMode: google.maps.DirectionsTravelMode.DRIVING
    };
  }

 $("#pageaddfeature3 .itPlg.addMapPlg .plgArea").gmap3('destroy');
$("#pageaddfeature3 .itPlg.addMapPlg .plgArea").gmap3({

  
   
  getroute:{
    options:objset,
    callback: function(results){

           
       
      if(results)
      {
 
      $(this).gmap3({
        map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
        directionsrenderer:{
          options:{
            directions:results
          }
        }
      });
      
      }else
      {   

      $(this).gmap3({
      map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
         marker:{
    values:genpointarr,
    options:{
      draggable: false
    }
      
      }
      
      });
    
      }
    
    }
  }
});
}
else if(Object.keys(genmappoint).length==1)
{
$("#pageaddfeature3 .itPlg.addMapPlg .plgArea").gmap3('destroy');
 $("#pageaddfeature3 .itPlg.addMapPlg .plgArea").gmap3({
      map:{
          options:{
            zoom: 17, 
            center: genmappoint[0]
          }
        },
         marker:{
    values:genpointarr,
    options:{
      draggable: false
    }
      
      }
      
      });

}
else
{
$('.itPlg.addMapPlg').hide();

}



}

function getactiondatatrip(actid)
{
nowactid=actid;
if(actid==1)
{
userid=myuserid;
fav=0;

}
else if(actid==2)
{
userid=0;
fav=myuserid;

}


//$.post()
if(actid==1||actid==2)
{
if(pagemainset==1)
{
var code='<div class="wrpAddNewMyTrip clearfix" style="left: 0.5px;" ><div>';
$(".wrpOutAddNewMyTrip").html(code);
}

var productxhr=$.get(serviceinfo+'getproduct', { page:pagemainset,userid:userid,fav:fav,nopoi:1 }, function(data) { 


 if(data.error.response)
         {
          alertbox(data.error.error);
         
         }else
         {
         var code='';
         if(data.data.length>0)
         {
         
         $.each(data['data'], function(key, value) {
         setproductidnow[value.productid]=value;
         
         code += '<div class="wrpInCell wrpInCellNewTrip w238" id="setproduct-'+value.productid+'"  style="margin:1px;width:214px;height:214px">\n';
         code += '<div class="ovlCell w238"></div>\n';
        code += '<img width="238" height="238" alt="img" src="'+value.simg.newpath+'" class="imgCell w238">\n';
        code += '<div class="ldTtlCell fs09 clTxtCell cutTxt">'+value.title+'</div>\n';
        code += '<div class="authCell clearfix fs03 clTxtCell">\n';
        code += '<img width="36" height="36" alt="User Image" class="imgUserCell" src="'+value.userssimg.newpath+'">\n';
        code += '<span class="authName cutTxt">'+value.displayname+'</span>\n';
        code += '</div>\n';
        code += '<div class="wrpLikeCell">\n';
        code += '<i class="ico icoUnLikeW"></i>\n';
        code += '<span class="numLikeCell fs03 clTxtCell">'+value.countlike+'</span>\n';
        code += '</div>\n';
        code += '<form class="timeNewTrip addTimeNewTrip w238" id="timeNewTrip-'+value.productid+'" style="display:none">\n';
        code += '<div class="ovlTimeNewTrip"></div>\n';
        code += '<div class="wrpTimeNewTrip">\n';
        code += '<button type="button" class="btnGen clTxtW cutTxt clBgBt1 fs04" onclick="linkto(\''+baseinfo+'/'+value.link+'/'+value.productid+'\')">View</button>\n';
        code += '<input type="text" placeholder="Start Time" id="timestart-'+value.productid+'" class="inpAddCtnt w120 clBg5 clBd2 fs03 clTxt2">\n';
        code += '<button type="button" onclick="selectproducttrip('+value.productid+')" class="btnGen btnTimeOk clTxtW cutTxt clBgSp2 fs04">OK</button>\n';
        code += '</div>\n';
        code += '</form>\n';
        
        
        code += '<form class="timeNewTrip shwTimeNewTrip w238" id="showtimeNewTrip-'+value.productid+'" style="display:none">\n';
        code += '<div class="wrpTimeNewTrip">\n';
        code += '<button type="button" class="btnGen btnDSlct clTxtW cutTxt clBgBt1 fs04" onclick="selecteditproducttrip('+value.productid+')">Deselect</button>\n';
        code += '<div class="shwTimeAddNewTrip fs18 clTxt2"><span id="shwTimeAddNewTrip-'+value.productid+'">10.00 AM</span></div>\n';
        code += '<button type="button" onclick="selecteditproducttrip('+value.productid+')" class="btnGen btnEditTime clTxtW cutTxt clBgSp2 fs04">Edit Time</button>\n';
        code += '</div>\n';
        code += '</form>';
        
        code += '</div>';
         
         
         });
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip").append(code);
         enddata=0;
         
         
         if(pagemainset==1)
         {
         
         
         $('.bodyAddNewTrip.clBg4.clBd2.bdFull').bind('scroll', function()
                              {
                                if($(this).scrollTop() + 
                                   $(this).innerHeight()
                                   >= $(this)[0].scrollHeight)
                                {
                                  
                                  if(enddata==0)
                                  {
                                    enddata=1;
                                    pagemainset++;
                                    getactiondatatrip(nowactid);
                                    
                                    //console.log('end reached');
                                  
                                  }
                                  
                                }
                              });
         }
         
         $('.wrpInCell.wrpInCellNewTrip.w238').each(function( index ) {
         
         
           $(this).hover(
                function() {
                   $(this).find('.timeNewTrip.addTimeNewTrip.w238').fadeIn();
              //  $( this ).append( $( "<span> ***</span>" ) );
                }, function() {
                    if($(this).find('.timeNewTrip.addTimeNewTrip.w238').hasClass("selectedtrip"))
                    {
                    
                    
                    }else
                    {
                    $(this).find('.timeNewTrip.addTimeNewTrip.w238').fadeOut();
                    }
                    
                    
                    
                    
              //  $( this ).find( "span:last" ).remove();
                }
                );
         
         
         });        
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip .inpAddCtnt").datepicker( "destroy" ); 
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip .inpAddCtnt").click(function() {
            var idtimetrip=$(this).attr("id");
             var rownid=idtimetrip.split("-"); 
             if($("#timeNewTrip-"+rownid[1]).hasClass("selectedtrip"))
             {
             
             }else
             {
             $("#timeNewTrip-"+rownid[1]).addClass("selectedtrip");
             
             }
             
         
            });
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip .inpAddCtnt").timepicker({onClose: function(dateText, inst) {

         var idtimetrip=$(this).attr("id");
             var rownid=idtimetrip.split("-"); 
             if($("#timeNewTrip-"+rownid[1]).hasClass("selectedtrip"))
             {
             $("#timeNewTrip-"+rownid[1]).removeClass("selectedtrip");
             }

        
               
                }
                
                }); 
         
         
         
         }else
         {
         if(pagemainset==1)
         {
         
         code += '<div class="nodata clTxt2 fs03">\n';
         if(actid==1)
         {
         code +='<span>No Post. Click <a class="clSp1"  href="javascript:void(0)" onclick="$(\'.btnAddSB.fs05.clBd2.cutTxt\').trigger(\'click\')">New Post</a> to create.</span>'
         }else
         {
         code += '<span>No Favorite.</span>\n';
         
         }
         
         code += '</div>';
         
         $(".wrpOutAddNewMyTrip .wrpAddNewMyTrip").append(code);
         
         }
         
         enddata=1;
         
         }
         
         
         
         
         
         
         
         
         
         
         
         
         
         
         
       
         
         
         }



});
}


}

var rownowtripdata=0;
function deletetriptime(rownowtripdataset)
{
$("#wrpInNewTrip-"+rownowtripdataset).remove();

var rowremove=0;
$.each($('.pointTrip.classpoint .clTxtW.fs02'), function(index ) { 

           $(this).html(pointData[rowremove]);
           rowremove++;
});
genmapnewtrip();


}
function edittriptime(rownowtripdataset)
{
$("#wrpInNewTrip-"+rownowtripdataset+' form').fadeIn();


}
function saveedittimedata(rownowtripdataset,daysetdata)
{



var objectset=convertTo12Hrs("February 04, 2011 "+$('#settimedata-'+rownowtripdataset).val());
$("#wrpInNewTrip-"+rownowtripdataset+' .inpTimeTrip.clTxtW.fs03').html(objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch);
changetimedatatrip(daysetdata);
$("#wrpInNewTrip-"+rownowtripdataset+' form').fadeOut();

}
function  changetimedatatrip(daytimesettrip){

       
           var timeSet=new Array();
           var rowtime=0;
           var starttime=59;
           var lastiddata=daytimesettrip;
           
           
           
           
           
           $('#rowdaynumset-'+daytimesettrip+' input[name="settimedata[]"]').each(function( index ) {
                     

                     if($(this).val())
                     {
                     
                      var timeVal=$(this).val()+':'+'00';
                     
                     
                     }else
                     {
                     
                      var timeVal='23:59:'+starttime;  
                      
                      starttime--;
                     
                     }
                     
                     timeSet[rowtime]={};   
                      var setidattr=$(this).attr("id");
                      var rownid=setidattr.split("-"); 

                     var $cont =$("#wrpInNewTrip-"+rownid[1]).clone(true);
                     timeSet[rowtime]={timeset:timeVal,clonedata:$cont};
                     
                     rowtime++;
           
           });
           
           
           
           timeSet.sort(function(a, b) {
           return new Date( '1970/01/01 ' +a.timeset ) > new Date('1970/01/01 ' + b.timeset);
           });
           
            
            $("#rowdaynumset-"+lastiddata+' .plgAreaNewTrip.clearfix').html('');
            
           // console.log("#rowdaynumset-"+lastiddata+' .plgAreaNewTrip.clearfix');
            
            $.each(timeSet, function(index, value) {
             

          // $("#featuretriprow-"+lastiddata+' .plgAreaTrip').append(value.clonedata);
           
            value.clonedata.appendTo($("#rowdaynumset-"+lastiddata+' .plgAreaNewTrip.clearfix'));

             
             });
             
           $( "#rowdaynumset-"+lastiddata+' input[name="settimedata[]"]' ).datepicker( "destroy" ); 
           $("#rowdaynumset-"+lastiddata+' input[name="settimedata[]"]').timepicker({
                   onClose: function(dateText, inst) {

                   
                   var idtimetrip=$(this).attr("id");
                   var rownid=idtimetrip.split("-"); 
                   changetimedata(rownid[1]);
                   
                    }
    
            });  
            
           $('#rowdaynumset-'+lastiddata+' .wrpBtnAddNewTrip.wrpInNewTrip').remove();
          //  var $cont2=$('.plgAreaNewTrip.clearfix .wrpBtnAddNewTrip.wrpInNewTrip').clone(true);
          
          var code = '<div style="width:206px;height:206px;margin:1px" class="wrpBtnAddNewTrip wrpInCell wrpInNewTrip w158" onclick="       openpopupnewtrip('+lastiddata+')">\n';
          code += '<img src="'+baseinfo+'/img/newtrip.png" alt="img">\n';
          code += '<div class="addTxtNewTrip fs04 clTxt3 boldGen"><span>Anything Else?</span></div>\n';
          code += '</div>';
          
           $("#rowdaynumset-"+lastiddata+' .plgAreaNewTrip.clearfix').append(code);
            
            
            var rowremove=0;
            $.each($('.pointTrip.classpoint .clTxtW.fs02'), function(index ) { 

           $(this).html(pointData[rowremove]);
           rowremove++;
});

            var rowremove=1;
            $.each($('.pointTrip.classActity .clTxtW.fs02'), function(index ) { 

           $(this).html(rowremove);
           rowremove++;
});
             
             genmapnewtrip();
           //genmapdata();
           
}
function convertTo12Hrs(yourDateTime){
    var myDate = new Date(yourDateTime);
    var dtObject = new Object();
    var monthsCollection = {0:"January", 1:"February",2:"March",3:"April",4:"May",5:"June",6:"July",7:"August",8:"September",9:"October",10:"November",11:"December"};
    dtObject.year = myDate.getFullYear();
    dtObject.month = monthsCollection[myDate.getMonth()];
    dtObject.day = (myDate.getDate()<10)?"0"+myDate.getDate():myDate.getDate();
    dtObject.minutes = (myDate.getMinutes() < 10)? "0"+myDate.getMinutes():myDate.getMinutes();
    dtObject.seconds = (myDate.getSeconds() < 10)? "0"+myDate.getSeconds():myDate.getSeconds();
    // Check if hours are greater than 12? Its PM
    dtObject.ampmSwitch = (myDate.getHours() >= 12)? "PM":"AM";
    // Convert the hours
    dtObject.hour = (myDate.getHours() > 12)?myDate.getHours()-12:myDate.getHours();
    // Add the 0 as prefix if its less than 10
    dtObject.hour = (dtObject.hour < 10)? "0"+dtObject.hour:dtObject.hour;

    // Format back the string as it was or return the dtObject object or however you like. I am returning the object here
    return dtObject;
}
function selecteditproducttrip(productidset)
{

$('#showtimeNewTrip-'+productidset).hide();
$('#timeNewTrip-'+productidset).show();

}
function selectproducttrip(productidset)
{
if($('#timestart-'+productidset).val())
{
var objectset=convertTo12Hrs("February 04, 2011 "+$('#timestart-'+productidset).val());

//console.log(objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch);

$('#shwTimeAddNewTrip-'+productidset).html(objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch);
$('#showtimeNewTrip-'+productidset).show();
$('#timeNewTrip-'+productidset).hide();

}else
{
alertwrongboxmsgonly('Please Choose Time');

}


}
function openpopupnewtrip(daytrip)
{

daysettrip=daytrip;
pagemainset=1;
$(".ovlPopGen.wrpPopAddNewTrip").fadeIn();
if(nowactid!=0)
{
getactiondatatrip(nowactid);
}else
{
getactiondatatrip(1);
}


}
function editformnewtrip(datarow)
{
addformnewtrip();

var rownow= rowdiv-1;
var rowgnow2=1;

    
    $('#formaddfeature input[name="day[]"]').val(datarow.day);
    $('#formaddfeature input[name="night[]"]').val(datarow.night);
    $('#formaddfeature input[name="startdate[]"]').val(datarow.startdate2);
    $('#formaddfeature input[name="enddate[]"]').val(datarow.enddate2);
    
    $('#formaddfeature input[name="price[]"]').val(datarow.price);
    $('#formaddfeature input[name="saleprice[]"]').val(datarow.saleprice);
    $('#formaddfeature select[name="curid[]"]').val(datarow.curid);
    
    $('#formaddfeature select[name="curid[]"]').val(datarow.curid);
    $('#formaddfeature select[name="destination"]').val(datarow.proid);
    
    
    
    //console.log(rownow);
    if(datarow.samecontactprofile!="0")
    {
    $('#formaddfeature input[name="samecontactprofile[]"]').trigger('click');
    }
    else
    {
    $('#formaddfeature input[name="facebook[]"]').val(datarow.facebook);
    $('#formaddfeature input[name="twitter[]"]').val(datarow.twitter);
    $('#formaddfeature input[name="googleplus[]"]').val(datarow.googleplus);
    $('#formaddfeature input[name="website[]"]').val(datarow.website);
    $('#formaddfeature input[name="email[]"]').val(datarow.email);
    $('#formaddfeature input[name="phone[]"]').val(datarow.phone);
    $('#formaddfeature input[name="fax[]"]').val(datarow.fax);
    $('#formaddfeature textarea[name="etc[]"]').val(datarow.etc);
    
    }
    
    

    var dayint=parseInt($('input[name="day[]"]').val(),10);
    if(is_numeric($('input[name="day[]"]').val())&&dayint>0&&$('input[name="startdate[]"]').val()!="")
    {
        var newrow=0;
        var nrow=$('.addTripPlg').length;
        
        if(nrow==0)
        {
            newrow=dayint;
        
        }else if(dayint>nrow)
        {
           newrow= dayint-nrow;
        }else
        {
           if(nrow>dayint)
           {
            deleterow=nrow-dayint;
             
              for(var irow=0;irow<deleterow;irow++)
             {
             var nrow2=$('.addTripPlg').length;
             $('.addTripPlg').eq( nrow2-1 ).remove();
             
             }
           }
          
        
        }
        
        
        if(newrow)
        {

        
        var code='';
        for(var irow=0;irow<newrow;irow++)
        {
        
        code += '<div class="itPlg addTripPlg">\n';
        code += '<div class="wrpPlg clBg5 clBd2 bdFull">\n';
        code += '<div class="plgArea"></div>\n';
        code += '<div class="wrpOutAtcPlg">\n';
        code += '<div class="wrpAtcPlg">\n';
        code += '<div class="spnHdDayTrip clTxtW">\n';
        code += '<span class="fs03">Day 1</span><br>\n';
        code += '<span class="rcmSizeAdd fs01">24/05/2013</span>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '<div class="wrpPlgAreaTrip Clearfix">\n';
        code += '<div class="plgAreaNewTrip clearfix" style="left:.5px">\n';
        code += '<div class="wrpBtnAddNewTrip wrpInNewTrip"  style="width:206px;height:206px;margin:1px">\n';
        code += '<img alt="img" src="'+baseinfo+'/img/newtrip.png">\n';
        code += '<div class="addTxtNewTrip fs04 clTxt3 boldGen"><span>Anything Else?</span></div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>\n';
        code += '</div>';
        
        }
        $("#pageaddfeature3 .wrpAddCtnt.clBg4.clBd2.bdFull").append(code);
        
        }
        
        var startdateset=$('input[name="startdate[]"]').val();
        var n0=startdateset.split("/"); 
        var d1 = new Date(n0[2],parseInt(n0[1],10)-1,parseInt(n0[0],10));
    
        var rownum=0;
        
        $( ".addTripPlg" ).each(function( index ) {
            $(this).attr("id",'rowdaynumset-'+(rownum+1));
            $(this).find('span.fs03').html('Day '+(rownum+1));
            $(this).find('span.rcmSizeAdd.fs01').html(startdateset);
            $(this).find('.wrpBtnAddNewTrip.wrpInNewTrip').attr("onclick",'openpopupnewtrip('+(rownum+1)+')');
            
            
            

            d1.setTime(d1.getTime() +  ((0+1) * 24 * 60 * 60 * 1000));
            startdateset=d1.format("dd/mm/yyyy");
            
            rownum++;
        
        
        });
    
    
    }
    
    
    
    
var code="";    
var lengthall=0;
$.each(datarow['objdata'], function(keydata, valueobjdata) {    

if(Object.keys(valueobjdata).length>0)
{    


 $.each(valueobjdata, function(keydata, valuedata2) {
 //console.log(valuedata2);
 if(valuedata2['isactivity']=="0")
{


//$(".timeNewTrip.shwTimeNewTrip.w238:visible").each(function( index ) {





var value= valuedata2.data;

var code="";    
code += '<div class="wrpInCell wrpInNewTrip w158 setfeature" style="margin:1px;width:206px;height:206px" id="wrpInNewTrip-'+rownowtripdata+'">\n';

code += '<div class="ovlCellTrip w158"></div>\n';
code += '<img width="158" height="158" alt="img" src="'+value.simg.newpath+'" class="imgCell w158">\n';
code += '<div class="wrpTl wrpBtnEdtCell">\n';
code += '<div title="Remove" class="btnIco closeTl" onclick="deletetriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoCloseTl"></span>\n';
code += '</div>\n';
code += '<div title="Edit" class="btnIco edtCell" onclick="edittriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoEdtCell"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'+value.title+'</div>\n';

var timesetdata=valuedata2.timeset;
var objectset=convertTo12Hrs("February 04, 2011 "+timesetdata);
code += '<div class="inpTimeTrip clTxtW fs03"><span>'+objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch+'</span></div>\n';

//code += '<input type="hidden" value="'+$('#timestart-'+rownid)+'" alt="settimedata-'+rownowtripdata+'" name="settimedata[]">';


//code += '<div class="pointTrip classpoint">\n';
var checkpoint=0;
var latsettrip=0;
var lngsettrip=0;

if(valuedata2.data.plugins)
{
checkpoint=0;
$.each( valuedata2.data.plugins, function( key2, value2 ) {

if(value2.plugname=="map")
{

checkpoint=1;
latsettrip=value2.lat;
lngsettrip=value2.lng;


}

});


}

if(checkpoint==1)
{
code += '<div class="pointTrip classpoint">\n';

code += '<input type="hidden" value="'+latsettrip+'" name="latsetrip[]">';
code += '<input type="hidden" value="'+lngsettrip+'" name="lngsetrip[]">';
code += '<input type="hidden" value="'+valuedata2.productid+'" name="productidtrip[]">';




code += '<span class="clTxtW fs02">'+pointData[lengthall]+'</span>\n';
code += '</div>\n';
lengthall++;
}


code += '<form class="timeNewTrip addTimeNewTrip w238" style="display:none">\n';
code += '<div class="ovlTimeNewTrip"></div>\n';
code += '<div class="wrpTimeNewTrip">\n';
code += '<input type="text" value="'+timesetdata+'" id="settimedata-'+rownowtripdata+'" alt="'+valuedata2.day+'" name="settimedata[]" placeholder="Start Time" class="inpAddCtnt w120 clBg5 clBd2 fs03 clTxt2">\n';

code +='<input type="hidden" name="sproductid[]" value="'+valuedata2.sproductid+'" >';



code += '<button type="button" onclick="saveedittimedata('+rownowtripdata+','+valuedata2.day+')" class="btnGen btnTimeOk clTxtW cutTxt clBgSp2 fs04">OK</button>\n';
code += '</div>\n';
code += '</form>';

rownowtripdata++;


//code +='';

//code += '<span class="clTxtW fs02">A</span>\n';
//code += '</div>\n';
code += '</div>';




//});



$('.plgAreaNewTrip.clearfix').eq((parseInt(valuedata2.day,10)-1)).append(code);
changetimedatatrip(valuedata2.day);




}else
{

var code="";    
code += '<div class="wrpInCell wrpInNewTrip w158 setfeature" style="margin:1px;width:206px;height:206px" id="wrpInNewTrip-'+rownowtripdata+'">\n';

code += '<div class="ovlCellTrip w158"></div>\n';
code += '<img width="158" height="158" alt="img" src="'+valuedata2['simg']['newpath']+'" class="imgCell w158">\n';
code += '<div class="wrpTl wrpBtnEdtCell">\n';
code += '<div title="Remove" class="btnIco closeTl" onclick="deletetriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoCloseTl"></span>\n';
code += '</div>\n';
code += '<div title="Edit" class="btnIco edtCell" onclick="edittriptime('+rownowtripdata+')">\n';
code += '<span class="ico icoEdtCell"></span>\n';
code += '</div>\n';
code += '</div>\n';
code += '<div class="ldTtlCell ldTtlTrip fs05 clTxtCell cutTxt">'+valuedata2.title+'</div>\n';

var objectset=convertTo12Hrs("February 04, 2011 "+valuedata2.timeset);
//$('#shwTimeAddNewTrip-'+productidset).html(objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch);


code += '<div class="inpTimeTrip clTxtW fs03"><span>'+objectset.hour+'.'+objectset.minutes+' '+objectset.ampmSwitch+'</span></div>\n';





code += '<form class="timeNewTrip addTimeNewTrip w238" style="display:none">\n';
code += '<div class="ovlTimeNewTrip"></div>\n';
code += '<div class="wrpTimeNewTrip">\n';
code += '<input type="text" value="'+valuedata2.timeset+'" id="settimedata-'+rownowtripdata+'" alt="'+valuedata2.day+'" name="settimedata[]" placeholder="Start Time" class="inpAddCtnt w120 clBg5 clBd2 fs03 clTxt2">\n';

code +='<input type="hidden" name="sproductid[]" value="0" >';

code +='<input type="hidden" name="simgmid[]" value="'+valuedata2.imgmid+'" >';
code +='<input type="hidden" name="imgmid[]" value="'+valuedata2.simgmid+'" >';



code +='<textarea  name="descritionset[]" style="display:none"  >'+valuedata2.description+'</textarea>';

code += '<button type="button" onclick="saveedittimedata('+rownowtripdata+','+valuedata2.day+')" class="btnGen btnTimeOk clTxtW cutTxt clBgSp2 fs04">OK</button>\n';
code += '</div>\n';
code += '</form>';


rownowtripdata++;


//code +='';

//code += '<span class="clTxtW fs02">A</span>\n';
//code += '</div>\n';
code += '</div>';

$('.plgAreaNewTrip.clearfix').eq((parseInt(valuedata2.day,10)-1)).append(code);
changetimedatatrip(valuedata2.day);



}

 });

 
 }


});


    
    
//       
//       
//    $('#feature'+rownow+' .image'+rowgnow2+' .plgArea').html('<a target="_blank" href="'+datarow.img.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"><img height="360" width="640" src="'+datarow.simg.newpath+'?t='+Math.floor((Math.random()*100000)+1)+'"></a>');
//    $('#feature'+rownow+' .image'+rowgnow2+' input[name="imgmid[]"]').val(datarow.imgmid);
//    $('#feature'+rownow+' .image'+rowgnow2+' input[name="simgmid[]"]').val(datarow.simgmid);
//    $('#feature'+rownow+' input[name="detail[]"]').val(datarow.detail);   


}

